home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.01 Jan 88 / basic source / DragGrayRect.BAS < prev    next >
Encoding:
BASIC Source File  |  1987-11-20  |  2.1 KB  |  82 lines  |  [TEXT/ZBAS]

  1. 'Drag Example
  2. 'By Dave Kelly
  3. '©MacTutor, 1988
  4.  
  5. WINDOW OFF
  6. COORDINATE WINDOW
  7. DEF MOUSE=-1
  8. DIM Rect%(3),pt%(1),pin%(3),bnd%(3),dir%,dis&
  9. pt%(0)=mousey%:pt%(1)=mousex%
  10. 'Create DragGrayRect function
  11. LONG FN DragGrayRect&(RL%,RT%,RR%,RB%,mousey,mousex,PL%,PT%,PR%,PB%,BL%,BT%,BR%,BB%,dir%)
  12. '    Rect%    =    the rectangle to be moved
  13. '    pt%    =    the point where the mouse was pushed.
  14. '    pin%    =    the rectangular limits in which the outline can be dragged.
  15. '    bnd%    =    the rectangular boundary for a drag.
  16. '    dir%    =    the direction to which the drag is constrained
  17. '            0 = no constraint, 1 = horizontal, 2 = vertical
  18. '    dis&    =    A point array that returns the drag displacement.
  19. CALL SETRECT(Rect%(0),RL,RT,RR,RB)
  20. CALL SETRECT(pin%(0),PL,PT,PR,PB)
  21. CALL SETRECT(bnd%(0),BL,BT,BR,BB)
  22. RgnHand&=FN NEWRGN
  23. CALL OPENRGN
  24. CALL FRAMERECT(Rect%(0))
  25. CALL CLOSERGN(RgnHand&)
  26. pt%(0)=mousey%:pt%(1)=mousex%:Proc&=0:dis&=0
  27. dis&=FN DRAGGRAYRGN(RgnHand&,pt%(0),pin%(0),bnd%(0),dir%,Proc&)
  28. CALL DISPOSERGN(RgnHand&)
  29. END FN=dis&
  30. 'Find out monitor size
  31. CALL GETWMGRPORT(WMgrPort&)
  32. PortTop=PEEK WORD(WMgrPort&+8)
  33. PortLeft=PEEK WORD(WMgrPort&+10)
  34. PortBottom=PEEK WORD(WMgrPort&+12)
  35. PortRight=PEEK WORD(WMgrPort&+14)
  36. WINDOW#1,"DragExample",(PortLeft+4,PortTop+42)-(PortRight-6,PortBottom-6),5
  37. MENU 1,0,1,"File"
  38. MENU 1,1,1,"Quit"
  39. top=100:left=100
  40. GOSUB "DrawBox"
  41. MOUSE ON:MENU ON:DIALOG ON
  42. ON MOUSE GOSUB "MouseEvent"
  43. ON MENU GOSUB "MenuEvent"
  44. ON DIALOG GOSUB "DialogEvent"
  45. "Loop"
  46. DO
  47. UNTIL Done
  48. MOUSE OFF:MENU OFF:DIALOG OFF
  49.  
  50. "DialogEvent"
  51. D=DIALOG(0)
  52. IF D=4 THEN END
  53. RETURN
  54.  
  55. "MenuEvent"
  56. Menunumber=MENU(0)
  57. Menuitem=MENU(1)
  58. IF Menunumber=1 AND Menuitem=1 THEN END
  59. MENU
  60. RETURN
  61.  
  62. "MouseEvent"
  63. X=MOUSE(0)
  64. mousey=MOUSE(2):mousex=MOUSE(1)
  65. IF mousey=0 AND mousex=0 THEN END
  66. dir%=0
  67. dis&= FN DragGrayRect&(left,top,left+100,top+100,mousey,mousex,PortLeft,PortTop,PortRight,PortBottom,PortLeft,PortTop,PortRight,PortBottom,dir%)
  68. dy=FN HIWORD(dis&)
  69. dx=FN LOWORD(dis&)
  70. LONG IF dx<>0 AND dy<>0
  71. CALL ERASERECT(Rect%(0))
  72. top=top+dy:left=left+dx
  73. GOSUB "DrawBox"
  74. END IF
  75. RETURN
  76.  
  77. "DrawBox"
  78. CALL SETRECT(Rect%(0),left,top,left+100,top+100)
  79. CALL FORECOLOR(205): ' color = red
  80. CALL PAINTRECT(Rect%(0))
  81. RETURN
  82.